 
layui.define(['form','laydate','xmSelect'], function(exports){
	var $ = layui.$
    ,form = layui.form
    ,setter = layui.setter
    ,xmSelect = layui.xmSelect
    ,laydate = layui.laydate;
	var menuSelect = xmSelect.render({
		el: '#menuSelect', 
		autoRow: true,
		name:'toChangeMenuId',
		filterable:true,
		radio: true,
		clickClose: true,
		tree: {
			show: true,
			showFolderIcon: true,
			showLine: true,
			strict: false,
			indent: 20,
			expandedKeys: true,
		},
		height: 'auto',
		on: function(data){
			if(data.isAdd){
				$('input[name=toChangePid]').val(data.change[0].pId);
			}
		}
	});
	var menuId = $('input[name=menuId]').val();//当前要编辑的menuId
	var pId = $('input[name=pId]').val();
  $.ajax({
	  url: setter.host+'/adminmanager/menu/queryTreeList'
      ,type:'get'
      ,dataType:'json'
      ,success: function(res){
        //请求成功后
    	  if(res.status == setter.response.statusCode.status_Success){
    		  menuSelect.update({
	      		  data: res.data,
	      		  autoRow: true,
	      	  })
	      	menuSelect.setValue([ pId]);
    	  }else{
    		  layer.msg(res.msg);
    	  }
      }
  });
  
    lay('#createTime').on('click', function(e){ //假设 test1 是一个按钮
    	  laydate.render({
    	    elem: '#createTime'
    	    ,show: true //直接显示
    	    ,closeStop: '#createTime' //这里代表的意思是：点击 test1 所在元素阻止关闭事件冒泡。如果不设定，则无法弹出控件
    	  });
    });
    
    form.on('select(typeSelect)',function (data){
    	if(data.value=='button'){
    		$('#url').val('add');
    		$('#menuName1').find("input").val('新增');
	    	$('#menuName1').css('display','none');
	    	$('#menuName2').css('display','block');
    	}else {
    		$('#url').val('');
    		$('#menuName1').find("input").val('');
	    	$('#menuName1').css('display','block');
	    	$('#menuName2').css('display','none');
    	}
    });
    form.on('select(buttonSelect)',function (data){
    	
    	if(data.value=='add'){
    		$('#menuName1').find("input").val('新增');
	    	$('#url').val('add');
			$('input[name="name"]').val('add');
    	}else if(data.value=='edit'){
    		$('#menuName1').find("input").val('编辑');
	    	$('#url').val('edit');
    	}else if(data.value=='batchdel'){
    		$('#menuName1').find("input").val('删除');
	    	$('#url').val('batchdel');
    	}else if(data.value=='export'){
    		$('#menuName1').find("input").val('导出');
	    	$('#url').val('export');
    	}
    });
    $("#about1").mouseover(function() {
    	layer.tips('设置该模块下的可见字段', this);
    });
	layui.admin.req({
        url: setter.host+'/adminmanager/menu/queryMenuField'
        ,type:'post'
        ,contentType: "application/json; charset=utf-8"
        ,data:'{"menuId":"'+menuId+'"}'
        ,done: function(res){
          //请求成功后
          if(res.status == setter.response.statusCode.status_Success){
        	  $('input[name="field"]').val(res.data.field);
          }else{
        	  layer.msg(res.msg);
          }
        }
      });
	$("#icon").click(function(){
		layer.open({
			type: 2,
			title:"图标管理 -- 当前共引入168个内置图标",
			area:['95%', '95%'],
			scrollbar:false,
			content:setter.host+'/adminmanager/menu/toIcons',
		});
		return false;
	});
  //对外暴露的接口
    exports('edit', {});
});